/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.testis.client;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;

/**
 *
 * @author nurhat
 */
public class GetIpsFromInterfaces {

    private static boolean isIP(String hostAddress) {
        return hostAddress.split("[.]").length == 4;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
         try {
             Enumeration<NetworkInterface> netfaces=NetworkInterface.getNetworkInterfaces();
             while(netfaces.hasMoreElements()){
                NetworkInterface netface =  netfaces.nextElement();
                Enumeration addresses = netface.getInetAddresses();
                while (addresses.hasMoreElements()) {
                    InetAddress ip = (InetAddress) addresses.nextElement();
                    if (!ip.isLoopbackAddress() && isIP(ip.getHostAddress())) {
                        System.out.println( ip.getHostAddress());
                    }
                }
             }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

}
